//
//  Dictionary+Extension.swift
//  JuMingNet
//
//  Created by wangjiayu on 2020/3/13.
//  Copyright © 2020 wangjiayu. All rights reserved.
//

import Foundation

extension Dictionary {

    // MARK: 字典转字符串
    func dictionartToString(_ dic:[String : Any]) -> String?{
        let data = try? JSONSerialization.data(withJSONObject: dic, options: [])
        let str = String(data: data!, encoding: String.Encoding.utf8)
        return str
    }


    // MARK: 字典转字符串
    func toJsonString() -> String? {
        guard let data = try? JSONSerialization.data(withJSONObject: self, options: []) else {
            return nil
        }
        
        guard let str = String(data: data, encoding: .utf8) else {
            return nil
        }
        
        return str
    }
}
